package com.code.day21;

import java.io.IOException;
import java.net.*;

public class Demo05Socket {
    public static void main(String[] args) throws IOException {
        //1、创建DatagramSocket对象
        DatagramSocket datagramSocket = new DatagramSocket();
        //2、准备数据
        byte[] bytes = "你好".getBytes();
        InetAddress ip = InetAddress.getByName("127.0.0.1");
        int port = 6666;
        //3、创建DatagramPacket对象
        DatagramPacket datagramPacket = new DatagramPacket(bytes, bytes.length, ip, port);
        //4、发送数据
        datagramSocket.send(datagramPacket);
        //5、关闭资源
        datagramSocket.close();
    }
}
